const collect = require('../modle/collect')

// 查询收藏
function findCollect(topics, callback) {
    collect.aggregate([{
            $lookup: {
                from: 'exercises',
                localField: 'exerciseId',
                foreignField: '_id',
                as: 'results'
            }
        },
        {
            $match: topics
        }
    ]).exec(function (err, result) {
        if (err) {
            console.log(err);
        }
        callback(result)
    })
}
//添加收藏
function addCollect({studentId,exerciseId},callback){
    collect.create({
        studentId ,
        exerciseId
    },function(err,res){
        callback(res)
    })
}

//取消收藏
function delCollect({studentId,exerciseId},callback){
    console.log(exerciseId);
    collect.deleteOne({studentId,exerciseId},function(err,res){
        callback(res)
    })
}
//  调用
module.exports = {
    findCollect,
    addCollect,
    delCollect
}